package fgame.resource
{
		
		import fgame.resource.decoder.Zf3dDecoder;
//		import fgame.resource.loader.MyZf3dLoader;
		
		import ricky.cache.Cache;
		import ricky.loader.MultipleLoader;
		import ricky.loader.Request;
		
		/**
		 * 模型资源池
		 */
		public class Model3DCache extends Cache
		{
			public function Model3DCache()
			{
				super();	
				_muliLoader=MultipleLoader.instance;
				var zf3dd:Zf3dDecoder=new Zf3dDecoder();
				_muliLoader.addProtool("zf3d",zf3dd);
				_muliLoader.addProtool("f3d",zf3dd);
				
//				_muliLoader.addLoader("zf3d",MyZf3dLoader);
			}
			
			/**
			 * 异步得到资源
			 * @param url:String 加载资源的地址
			 * @param onComplete:Function  function(req:Request):void回调函数
			 * @param priority:int=1 加载优先级 priority越大越优先
			 */
			override public function getResource(model:String,onComplete:Function,priority:int=1,head:*=null):void
			{
				var key:String;
				var url:String=model;//Utils.getModelUrl(model);
				var r:Request=new Request(url,onComplete,priority,url);
				r.head=head;
				key=r.key;
				if(_resMap[key])//如果有缓存
				{
					r.data=this.getValue(key);
					if(onComplete!=null)
						onComplete(r);
					return;
				}
				r.cache=_resMap;
				_muliLoader.addReqToQueue(r);
			}
			
			/**
			 * 卸载正在加载的资源
			 */
			override public function unloadResource(model:String):void
			{
				var re:Request=new Request(model);
				_muliLoader.unload(re);
			}
			
			private var _muliLoader:MultipleLoader;
			
			/**
			 * 得到实例
			 */
			public static function get instance():Model3DCache
			{
				if(_instance==null)
					_instance=new Model3DCache();
				return _instance;
			}
			
			private static var _instance:Model3DCache;
		}
}